<!-- 单据管理 -->
<template>
  <div>
    <ZgNewPage
      ref="page"
      :showInlineBtn="false"
      :uniqueName="uniqueName"
      :pageOpt="pageOpt"
      :dataBtns="dataBtns"
      :extraBtns="extraBtns"
      :headers="headers"
      :conditions="conditions"
      :adminWidth="200"
      @search="onSearch"
      @filter="onFilter"
      @header="mergeHeader"
      @admin="toAdmin"
      @extra="toExtra"
    >
      <template slot="columns">
        <a-table-column
          v-for="(h, i) in headers"
          :key="`column${i}`"
          :width="h.width === 0 ? 'auto' : h.width"
          align="centercenter"
          :title="h.label"
        >
          <template slot-scope="record">
            <template v-if="h.code === '8'">
              <span v-if="record[h.code] === '未盖章'" style="color: #f49229">{{ record[h.code] }}</span>
              <template v-else> {{ record[h.code] }}</template>
            </template>
            <template v-else-if="h.code === '9'">
              <span v-if="record[h.code] === '月计划'" style="color: #56b51d">{{ record[h.code] }}</span>
              <template v-else> {{ record[h.code] }}</template>
            </template>
            <template v-else>
              {{ record[h.code] }}
            </template>
          </template>
        </a-table-column>
      </template>
    </ZgNewPage>
  </div>
</template>
<script>
export default {
  data () {
    return {
      uniqueName: 'test',
      pageOpt: {
        showPageTitle: false,
        showConditionBtn: true,
        showHeaderConfig: false,
        showAttachBtn: false
      },
      conditions: [
        { code: 'name', compType: '单行文本', label: '市场公司', defaultVal: '' },
        { code: 'name', compType: '单行文本', label: '收费单位', defaultVal: '' },
        { code: 'month', compType: '日期', label: '年月-组件暂不支持', defaultVal: '' }
      ],
      headers: [
        { code: '1', label: '收获单位', isShow: true, sort: 0 },
        { code: '2', label: '市场公司', isShow: true, sort: 0 },
        { code: '3', label: '出卖人', isShow: true, sort: 0 },
        { code: '4', label: '合同编号', isShow: true, sort: 0 },
        { code: '5', label: '提交日期', isShow: true, sort: 0 },
        { code: '6', label: '年份', isShow: true, sort: 0 },
        { code: '7', label: '月份', isShow: true, sort: 0 },
        { code: '8', label: '盖章状态', isShow: true, sort: 0 },
        { code: '9', label: '类型', isShow: true, sort: 0 }
      ],
      dataBtns: [
        { key: 1, name: '详情', type: 'link', isShow: () => { return true } },
        { key: 2, name: '发送', type: 'link', isShow: () => { return true } }
      ],
      extraBtns: [{ key: 1, name: '去盖章', icon: 'user', type: 'primary' }]
    }
  },
  methods: {
    search () {
      const pageRef = this.$refs.page
      if (pageRef) {
        pageRef.search()
      } else {
        setTimeout(() => {
          this.search()
        }, 50)
      }
    },
    onSearch (param) {
      const diyHeaders = localStorage.getItem(this.currentUser.username + '_diyHeader_' + this.uniqueName)
      if (diyHeaders) {
        this.mergeHeader(JSON.parse(diyHeaders))
      }
      // 加载表头
      const list = [
        {
          key: '1',
          id: '1',
          1: '十大',
          2: '北方公司',
          3: '山西焦煤集团',
          4: '7987387428723',
          5: '2025-01-01',
          6: '2025',
          7: '07',
          8: '未盖章',
          9: '月计划'
        }
      ]
      this.$refs.page.endSearch({
        total: list.length,
        list: list
      })
    },
    toAdmin (opt) {
      if (opt.key === 1) {
        alert('详情')
      } else {
        this.confirm(() => {
          // this.$http.post('/zg-system/attach/del', [param.obj.id], () => {
          //   this.$refs.page.search()
          // })
        }, '确定要删除这条数据么')
      }
    },
    toExtra (opt) {
      alert('去盖章')
    },
    onFilter (f, param) {},
    mergeHeader (newHeaders) {
      if (!newHeaders) {
        return
      }
      this.headers = newHeaders
        .filter((t) => {
          return t.isShow
        })
        .sort((a, b) => {
          return a.sort - b.sort
        })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
